package com.water.camera.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.DialogDmEditContentBinding;
import com.water.camera.util.Utils;

public class EditDlg extends FullScreenDlg {

    DialogDmEditContentBinding binding;
    EditItem item;

    public EditDlg setData(EditItem item) {
        this.item = item;
        return this;
    }

    @Override
    protected int getHeight() {
        return Utils.getScreenHeight() / 2;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DialogDmEditContentBinding.inflate(inflater, container, false);
        binding.ivClose.setOnClickListener(v -> dismiss());
        binding.tvTitle.setText(item.name);
        if (!TextUtils.isEmpty(item.value)) {
            binding.etContent.setText(item.value);
        }
        binding.btnSave.setOnClickListener(v -> {
            item.updateValue(binding.etContent.getText().toString().trim());
            dismiss(true, item);
        });
        return binding.getRoot();
    }
}
